package com.dzxcqmxm.servlet.user;

import com.dzxcqmxm.Dao.UserDao;
import com.dzxcqmxm.Dao.impl.UserDaoImpl;
import com.dzxcqmxm.HelloServlet;
import com.dzxcqmxm.JB.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Payboi
 * @create 2022/6/2-22:00
 * @FileName findAllUserServlet
 * @Description
 */
@WebServlet("/indexUserServlet")
public class indexUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDao userDao = new UserDaoImpl();
        User user = new User();

        ArrayList<User> userArrayList = new ArrayList<User>();
        try {
            userArrayList = userDao.findAllUser();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //就是把我们获取到的列表给设置成一次session会话，让它可以在jsp的会话中获取到。
        request.getSession().setAttribute("userArrayList",userArrayList);

        request.getRequestDispatcher("/admin/user/indexUser.jsp").forward(request,response);

    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            doPost(request, response);
        } catch (ServletException e) {

        }
    }
}
